/*
 * @Date: 2022-02-14 11:24:10
 * @LastEditors: 春贰
 * @gitee: https://gitee.com/chun22222222
 * @github: https://github.com/chun222
 * @Desc:
 * @LastEditTime: 2023-11-16 15:46:05
 * @FilePath: \go-easy-dashboard\system\controller\base\main.go
 */
package base

import (
	"github.com/gin-gonic/gin"
	"go-easy-dashboard/system/core/request"
	"go-easy-dashboard/system/core/response"
	"go-easy-dashboard/system/model/CommonModel"
	"go-easy-dashboard/system/model/RequestModel"
	"go-easy-dashboard/system/service/BaseService"
)

var loginService BaseService.LoginService

func Login(c *gin.Context) {
	var r RequestModel.Login
	err, msg := request.Binding(&r, c)
	if err != nil {
		response.FailWithMessage(msg, c)
		return
	}

	r.Ip = c.ClientIP()
	err, u := loginService.Login(r)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	response.OkWithDetailed(u, "sucess", c)

}

//日志列表
func LoginLog(c *gin.Context) {
	var r RequestModel.LoginLog
	err, msg := request.Binding(&r, c)
	if err != nil {
		response.FailWithMessage(msg, c)
		return
	}

	if err, list, total := loginService.LoginLog(r); err != nil {
		response.FailWithMessage(err.Error(), c)
	} else {
		response.OkWithData(
			CommonModel.PageResult{
				List:     list,
				Total:    total,
				Page:     r.Page,
				PageSize: r.PageSize,
			}, c)
	}
}
